<template>
  <div>
    <el-container>
      <el-header>
        <div class="header">
          <el-menu
              router
              class="el-menu-demo"
              mode="horizontal"
              @select="handleSelect"
              background-color="#545c64"
              text-color="#fff"
              active-text-color="#ffd04b">
            <div class="header-title">
              <h1 style="color: white">Food Bear</h1>
            </div>
            <el-menu-item index="/foodIndex" :class="$route.path==='/foodIndex'?'is-active':''">首页</el-menu-item>
            <div class="header-user" v-if="login">
              <el-link :underline="false" href="/login"><span style="color: white">请登录</span></el-link>
            </div>
            <div class="header-user" v-if="!login">
              <template>
                <el-dropdown @command="handleCommand">
                <span class="el-dropdown-link" style="color: white">
                  欢迎！{{name}}<i class="el-icon-arrow-down el-icon--right"></i>
                </span>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item >退出登录</el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </template>
            </div>
          </el-menu>
        </div>
      </el-header>
      <el-container>
        <el-aside width="16%" style="margin-top: 20px;height: 650px">
          <el-menu
              router
              class="el-menu-vertical-demo"
              @open="handleOpen"
              @close="handleClose">
            <el-submenu index="1">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>服务</span>
              </template>
              <el-menu-item index="/orderListRecordAgency" :class="$route.path==='/orderListRecordAgency'?'is-active':''">记录</el-menu-item>
              <el-menu-item index="/appealApproval" :class="$route.path==='/appealApproval'?'is-active':''">申诉审批</el-menu-item>
            </el-submenu>
            <el-menu-item index="/agencyBossReviewProgress" :class="$route.path==='/agencyBossReviewProgress'?'is-active':''">
              <i class="el-icon-info"></i>
              <span slot="title">审核进度</span>
            </el-menu-item>
            <el-menu-item index="/agencyBossMessage" :class="$route.path==='/agencyBossMessage'?'is-active':''">
              <i class="el-icon-setting"></i>
              <span slot="title">个人信息</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "AgencyBossManager",
  data(){
    return{
      activeIndex: '',
      name: '',
      login: false
    }
  },
  methods:{
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleCommand(command) {
      this.$confirm('此操作将退出登录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        sessionStorage.removeItem("agency")
        location.href = "/"
        this.$message({
          type: 'success',
          message: '退出成功!'
        });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    }
  },
  mounted() {
    this.activeIndex = this.$route.path
    let agency = JSON.parse(sessionStorage.getItem("agency"));
    let boss = JSON.parse(sessionStorage.getItem("boss"));
    if (agency !== null) {
      this.name = agency.aname
      return
    }
    if (boss !== null) {
      this.name = boss.bname
      return;
    }
    this.login = !this.login
  }
}
</script>

<style scoped>
.el-header {
  padding: 0;
}

.el-menu-demo {
  display: flex;
  flex-direction: row;
}

.header-title {
  padding-right: 50px;
  padding-left: 50px;
}

.header-user {
  margin-left: 950px;
  margin-top: 20px;
  color: white;
}
</style>
